
public class PrintEnvObject extends EnvTreeNode implements PEObject{

	public PrintEnvObject() {
		super("<PE:Print>");
	}

	public String apply(String param1, String param2){
		if (param1.contains("lambda")){
			System.out.print("[lambda closure: " + param1.split(":")[2] + ": " + param1.split(":")[1] + "]");
		}else if ( param1.equals("<true>") | 
				param1.equals("<false>") | 
				param1.equals("<nil>") | 
				param1.equals("<dummy>") ){
			printPrimitive(param1);
		}else if ( param1.substring(0,7).equals("$$tau::") ){
			printTuple(param1);
		}else if ( param1.substring(0,5).equals("<STR:") ){
			printString(param1);
		}else{
			printPrimitive(param1);
		}
		return "<dummy>";
	}
	
	/*
	 * <STR:'disfy'>
	 */
	private void printString(String param1) {
		param1 = param1.split(":")[1];
		//param1 = param1.replace('<', ' ');
		//param1 = param1.replace('>', ' ');
		param1 = handleEscape(param1);
		param1 = param1.trim();
		//if (param1.contains(":")){
			String str = param1;//.split(":")[1];
			str = str.substring(1,str.length()-2);
			System.out.print(str);
		//}else{
		//	System.out.print(param1);
		//}
	}

	private String handleEscape(String param1) {
		return param1.replace("\\t","\t").replace("\\n", "\n");
	}

	private void printTuple(String param1) {
		System.out.print((new StackTupleHandler(param1)).print());
	}

	void printPrimitive(String param1){
		param1 = param1.replace('<', ' ');
		param1 = param1.replace('>', ' ');
		param1 = param1.trim();
		if (param1.contains(":")){
			System.out.print(param1.split(":")[1]);
		}else{
			System.out.print(param1);
		}
	
	}
}
